<template>

  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="8">
			<p-form-item label="送检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inspectBillno', validatorRules.inspectBillno]" placeholder="请输入送检单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="mid,mcode,mname,sprc,mexplain"
						dest-fields="mid,mcode,mname,sprc,mexplain"
						code="mes_cpinfo_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入物料名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="当前地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'currentAddress', validatorRules.currentAddress]" placeholder="请输入当前地址"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="来料方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['inMethod', validatorRules.inMethod]" :trigger-change="true" dictCode="mes_in_method" placeholder="请选择来料方式"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送货单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sendBillno', validatorRules.sendBillno]" placeholder="请输入送货单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'workBillno', validatorRules.workBillno]" placeholder="请输入工单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'sendInspectQty', validatorRules.sendInspectQty]" placeholder="请输入送检数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择送检时间" v-decorator="[ 'sendInspectTime', validatorRules.sendInspectTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="检验剩余时长" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'inspectTimeRemain', validatorRules.inspectTimeRemain]" placeholder="请输入检验剩余时长" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sendInspectBy', validatorRules.sendInspectBy]" placeholder="请输入送检人员"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="计划加急" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-switch  placeholder="String" v-decorator="['planUrgent']" field="planUrgent" dictCode="" @callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料大类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mbig', validatorRules.mbig]" placeholder="请输入物料大类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料小类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'msmall', validatorRules.msmall]" placeholder="请输入物料小类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="检验方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['inspectMethod', validatorRules.inspectMethod]" :trigger-change="true" dictCode="rc_inspect_method" placeholder="请选择检验方式"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料管控方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'matSn', validatorRules.matSn]" placeholder="请输入物料管控方式"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="供应商信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'custname', validatorRules.custname]" placeholder="请输入供应商信息"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="供应商代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-code"
						v-decorator="['custno', validatorRules.custno]"
						:trigger-change="true"
						org-fields="custid,custno,custname"
						dest-fields="custid,custno,custname"
						code="mes_get_superinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="抽检数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'simpleQty', validatorRules.simpleQty]" placeholder="请输入抽检数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="采购单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'pbillno', validatorRules.pbillno]" placeholder="请输入采购单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="问题备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'questionRemark', validatorRules.questionRemark]" placeholder="请输入问题备注"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="供应商报告" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'custReport', validatorRules.custReport]" placeholder="请输入供应商报告"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="封样图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'photoUrl', validatorRules.photoUrl]" placeholder="请输入封样图片"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="技术规格书" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'tcsp', validatorRules.tcsp]" placeholder="请输入技术规格书"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'fileUrl', validatorRules.fileUrl]" placeholder="请输入附件"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="当前处理人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'currentHandler', validatorRules.currentHandler]" placeholder="请输入当前处理人"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction, putAction, api } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import fSwitch from '@/components/switch'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesQcIncomeBasicInfoModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JDictSelectTag,
      fSwitch,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        inspectBillno:{rules: [{ required: false, message: '请输入送检单号!' }]},
        mcode:{rules: [{ required: false, message: '请输入物料编码!' }]},
        mname:{rules: [{ required: false, message: '请输入物料名称!' }]},
        currentAddress:{rules: [{ required: false, message: '请输入当前地址!' }]},
        inMethod:{rules: [{ required: false, message: '请输入来料方式!' }]},
        sendBillno:{rules: [{ required: false, message: '请输入送货单号!' }]},
        workBillno:{},
        sendInspectQty:{rules: [{ required: false, message: '请输入送检数量!' }]},
        sendInspectTime:{rules: [{ required: false, message: '请输入送检时间!' }]},
        inspectTimeRemain:{rules: [{ required: false, message: '请输入检验剩余时长!' }]},
        sendInspectBy:{rules: [{ required: false, message: '请输入送检人员!' }]},
        planUrgent:{},
        mbig:{rules: [{ required: false, message: '请输入物料大类!' }]},
        msmall:{rules: [{ required: false, message: '请输入物料小类!' }]},
        inspectMethod:{},
        matSn:{},
        custname:{rules: [{ required: false, message: '请输入供应商信息!' }]},
        custno:{rules: [{ required: false, message: '请输入供应商代码!' }]},
        simpleQty:{},
        pbillno:{},
        questionRemark:{},
        custReport:{},
        photoUrl:{rules: [{ required: false, message: '请输入封样图片!' }]},
        tcsp:{rules: [{ required: false, message: '请输入技术规格书!' }]},
        fileUrl:{rules: [{ required: false, message: '请输入附件!' }]},
        currentHandler:{rules: [{ required: false, message: '请输入当前处理人!' }]},
        },
        url: {
          add: '/mes-quality/mesQcIncomeBasicInfo/add',
          edit: '/mes-quality/mesQcIncomeBasicInfo/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
        this.getRuleCodeValue();
      },
      getRuleCodeValue() {
        let param = {
          commonFormData: this.model,
          rules: [
            {"ruleCode": "mes_inspect_billno", "columnName": "inspectBillno"},
            ]
        }

        putAction(api.ruleBaseURL, param).then(res => {
          // 执行成功，获取返回的值，并赋到页面上
          if (res.success) {
            console.log("生成的编码：" + res.data)
            const item = res.data;
            this.form.setFieldsValue(pick(item, Object.keys(item)))
          }
        })
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'inspectBillno','mcode','mname','currentAddress','inMethod','sendBillno','workBillno','sendInspectQty','sendInspectTime','inspectTimeRemain','sendInspectBy','status','inspectResult','inspectTimes','priority','matStatus','planUrgent','mbig','msmall','inspectMethod','matSn','custname','custno','simpleQty','pbillno','questionRemark','custReport','photoUrl','tcsp','fileUrl','currentHandler','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'inspectBillno','mcode','mname','currentAddress','inMethod','sendBillno','workBillno','sendInspectQty','sendInspectTime','inspectTimeRemain','sendInspectBy','status','inspectResult','inspectTimes','priority','matStatus','planUrgent','mbig','msmall','inspectMethod','matSn','custname','custno','simpleQty','pbillno','questionRemark','custReport','photoUrl','tcsp','fileUrl','currentHandler','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>
